const app = getApp()
Page({
  data: {
    loading: true,
    page: 0,
    id: 0,
    special: [],
    shop: []
  },
  //监听页面加载
  onLoad: function(options) {
    app.getParam(options,(param) => {
      this.setData({
        id: param.id,
      });
      this.getitem(param.id);
    })
  },
  //上拉加载
  onReachBottom: function() {
    this.setData({
      loading: true,
    });
    this.getitem(this.data.id);
  },
  //点击请求数据
  getitem: function (id) {
    if (this.data.loading) {
      var param = {
        id: id,
        page: this.data.page + 1
      }
      app.api().Get('api/v4/allwin/shop/special',param,(result)=>{
        if (result.code == 200) {
          var shop = this.data.shop;
          for (let i in result.data.shop) {
            shop.push(result.data.shop[i]);
          }
          this.setData({
            shop: shop,
            page: param.page,
          });
          if (param.page == 1){
            this.setData({
              special: result.data.special
            });
          }
        }
        this.setData({
          loading: false,
        });
      })
    }
  },
  //分享按钮
  onShareAppMessage: function () {
    var special = this.data.special;
    return {
      title: special.content,
      imageUrl: special.picture,
      path: '/pages/shop/index?ucode=' + app.globalData.loginuser.ucode + '&id=' + this.data.special.id
    }
  } 
})